<?php
defined('IN_XLP') or exit('Access Denied');
$Document = array(
    'pageid'   => 'event-edit', //页面标示
    'pagename' => '编辑活动', //当前页面名称
    'mycss'    => array('../jquery-ui/css/smoothness/jquery-ui-1.10.0.custom.min'), //加载的css样式表
    'myjs'     => array(), //加载的js脚本
    'footerjs' => array(
        '../jquery-ui/js/jquery-ui-1.10.0.custom.min',
        '../jquery-ui/js/jquery-ui-timepicker-addon',
        // 'content/jquery-1.7.2.min',
        // 'task/pic_preview',
    ),
    'head'     => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<style>
label{cursor:pointer;font-weight:normal}
.red{color:red;}
.pt7{padding-top:7px;}
.w70{width:70px;display:inline;}
.w100{width:100px;display:inline;}
#ui-datepicker-div{z-index:10000 !important;}
</style>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->
<section id="content">
    <section class="main padder">
        <div class="clearfix">
            <h4><i class="fa fa-edit"></i>新增活动</h4>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <div class="panel-body">
                        <form class="form-horizontal" id="eventEditForm" method="post" autocomplete="off">
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label">活动标题</label>
                                <div class="col-sm-2">
                                    <input type="text" name="event_title" id="event_title" placeholder="" value="<?php echo $event['event_title'] ?>" class="form-control" />
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label">活动ID</label>
                                <div class="col-sm-2">
                                    <input type="text" name="event_id" id="event_id" placeholder="" value="<?php echo $event['event_id'] ? $event['event_id'] : ''; ?>" class="form-control" />
                                </div>
                            </div>

                            <!-- <div class="form-group">
                                <label class="col-sm-1 control-label">活动横幅</label>
                                <div class="col-lg-9 media">
                                    <div id="shop_logo" class="bg-light pull-left text-center media-large thumb-large"></div>
                                    <div class="media-body" style="display:inline-block;margin-left:15px;">
                                        <a class="file-input-wrapper btn btn btn-sm btn-info m-b-small">
                                            选&nbsp;择<input id="slogo" type="file" name="shop_logo" class="btn btn-sm btn-info m-b-small" style="left:-175px;top:0px;position:absolute;opacity:0;z-index:99;">
                                        </a><br>
                                        <a class="btn btn-sm btn-default">上&nbsp;传</a>
                                    </div>
                                </div>
                            </div> -->

                            <div class="form-group"> 
                                <label class="col-sm-1 control-label">活动图片</label> 
                                <div class="col-sm-3">
                                    <input type="text" name="event_banner" id="event_banner" placeholder="" value="<?php echo $event['event_banner'] ?>" class="form-control"  />
                                    <span class="help-block">请上传您的活动图片，建议尺寸600px*170px</span>
                                </div>
                                <div class="col-sm-3">
                                    <iframe width="280" height="24" src="<?php echo U('upload/index',array('id'=>'event_banner')); ?>" scrolling="no" frameborder="0"></iframe>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label">活动链接</label>
                                <div class="col-sm-2">
                                    <input type="text" name="event_link" id="event_link" placeholder="" value="<?php echo $event['event_link'] ?>" class="form-control" />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label">起始时间</label>
                                <div class="col-sm-3">
                                    <input class="input-sm" style="display:inline" name="time_start" id="time_start" size="18" type="text" value="<?php echo $event['time_start'] ?>" readonly>
                                    <span>&emsp;&#8764&emsp;</span>
                                    <input class="input-sm" style="display:inline" name="time_end" id="time_end" size="18" type="text" value="<?php echo $event['time_end'] ?>" readonly>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label">顺序号</label>
                                <div class="col-sm-2">
                                    <input type="text" name="event_sort" id="event_sort" placeholder="0~255，数字越小越靠前" value="<?php echo $event['event_sort'] ?>" class="form-control" />
                                </div>
                            </div>

                            <div class="form-group pt7">
                                <div class="col-sm-9 col-lg-offset-1">
                                    <div class="col-sm-1">
                                        <input type="hidden" name="id" value="<?php echo $event['id'] ?>">
                                        <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                                    </div>
                                    <button type="button" class="btn btn-white">取消</button>
                                </div>
                            </div>

                        </form>
                    </div>
                </section>
            </div>
        </div>
    </section>
</section>
<!--/ content --> 
<!--主体 结束-->
<?php include getTpl('footer', 'public'); ?>
<script>
var uploadUrl = "<?php echo U('task/upload');?>";
//图片预览插件中用了$.browser 该特性不在jquery1.9之后支持
// var jQuery_1_7_2 = $.noConflict(true);

$(function(){
    $('#eventEditForm').submit(function(){

        if($.trim($('#event_title').val()) == '') {
            Msg.error('活动标题不能为空');
            resetSubmit("#sub-ok", '提交');
            return false;
        }

        if($.trim($('#event_id').val()) == '') {
            Msg.error('活动ID不能为空');
            resetSubmit("#sub-ok", '提交');
            return false;
        }
        
        if($.trim($('#event_banner').val()) == '') {
            Msg.error('活动横幅不能为空');
            resetSubmit("#sub-ok", '提交');
            return false;
        }

        if($.trim($('#event_link').val()) == '') {
            Msg.error('活动链接不能为空');
            resetSubmit("#sub-ok", '提交');
            return false;
        }

        if($.trim($('#time_start').val()) == '' || $.trim($('#time_end').val()) == '') {
            Msg.error('起始时间不能为空');
            resetSubmit("#sub-ok", '提交');
            return false;
        }

        Msg.loading();
        $.post('<?php echo U("task/edit_event"); ?>', $(this).serialize(), function(result){
            Msg.hide();
            resetSubmit("#sub-ok", '提交');
            if(result.status == 1) {
                Msg.ok(result.info);
                self.location.href = "<?php echo U('content/task/event') ?>";
            } else {
                Msg.error(result.info);
            }
        }, 'JSON');

        return false;
    });

    //时间插件
    $('#time_start').datetimepicker();
    $('#time_end').datetimepicker();
    //上传图片
    // jQuery_1_7_2("#slogo").uploadPreview({width:120,height:120,imgDiv:"#shop_logo"});

});
</script>